home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / jemtex2.zip / JEM2TEX.C < prev    next >
C/C++ Source or Header  |  1991-04-14  |  48KB  |  1,318 lines

  1. /* -mt -f -A -K -G -O -w */
  2. /* Compile with Turbo-C 2.0 */
  3. /*
  4.   This program translates a .JEM file into a .TeX file
  5.  
  6.   Author: Francois Jalbert
  7.               '
  8.   Date: November 1990 
  9.  
  10.   Version: 1.0
  11.  
  12.   Date: January 1991
  13.  
  14.   Version: 1.01
  15.  
  16.   Modifications: - Added \hskip0pt plus0.1em between all Japanese symbols which 
  17.                    improved dramatically line breaks and inter-sentence spacing 
  18.                    since [La]TeX could only add glue between whole Japanese 
  19.                    sentences. 
  20.                  - Extra space after punctuation is now an option since it is 
  21.                    not desirable with MuTeX when the text is to go under the
  22.                    staff. 
  23.                  - Font names now use only small letters to be compatible with 
  24.                    the fontlib program supplied with emTeX. 
  25.                  - Command line parameters now supported.
  26.                  - Run-time parameters now supported.
  27.                  - Updated and improved run-time messages.
  28.  
  29.   Date: April 1991
  30.  
  31.   Version: 2.00
  32.  
  33.   Modifications: - Added four kanjis.
  34.                  - If desired, only standard JIS '83 characters are allowed.
  35.                  - If desired, a % is added at each Japanese end of line.
  36.                  - Three file name extensions .JEM .JPN .JAP now supported.
  37.                  - Default extension is .JEM and the program has been renamed.
  38.                  - Three run-time parameter flags now supported.
  39.                  - Japanese comments not translated anymore for reference.
  40.                  - Hyphenation and glue handled separately for better control.
  41.                  - More clever algorithm for Japanese hyphenation.
  42.                  - Space after some punctuation now obtained with \eeee.
  43.                  - Small space around some punctuation introduced with \eee.
  44.                  - Tiny space between Japanese characters with \ee.
  45.                  - Space between Japanese and Roman with \eeee and \eee.
  46.                  - Symbols separated only by [La]TeX comments are now 
  47.                    recognized as consecutive.
  48.                  - MS-kanji (Shift-JIS) now supported.
  49.  
  50.   Error Levels: 0 - Normal termination.
  51.                 1 - Error.
  52. */
  53.  
  54. #include <stdio.h>
  55. #include <string.h>
  56. #include <ctype.h>
  57. #ifdef __TURBOC__
  58. #include <process.h>
  59. #endif
  60.  
  61. #define True  1
  62. #define False 0
  63. /* Highest Bitmap number in JIS24 */
  64. #define BitmapMax 7806
  65. /* Highest font number */
  66. #define FontMax   60 /* Floor of 7806 Div 128 */
  67. /* Highest size number */
  68. #define SizeMax   7 /* magsteps are 0, 0.5, 1, 2, 3, 4, 5 */
  69. /* DOS file name length */
  70. #define FileNameDOS  250 /* includes path */
  71. #define ExtensionDOS 4   /* includes . */
  72. #define TotalNameDOS 254
  73. /* File name extensions in priority order */
  74. char Extension1[]=".jem";
  75. char Extension2[]=".jpn";
  76. char Extension3[]=".jap";
  77. /* Run-time flag of all the same length */
  78. char RunFlag1[]="JEM2TEX";
  79. char RunFlag2[]="JPN2TEX";
  80. char RunFlag3[]="JAP2TEX";
  81. /* Parameter flag */
  82. #define Flag1 '/' /* DOS style */
  83. #define Flag2 '-' /* UNIX style */
  84. /* Parameter keywords in approximate decreasing length order */
  85. #define ParamMax 12
  86. char Space1[]="EXTRASPACE";
  87. char Space2[]="EXTRA";
  88. char Space3[]="SPACE";
  89. char NoSpace1[]="NOEXTRASPACE";
  90. char NoSpace2[]="NOEXTRA";
  91. char NoSpace3[]="NOSPACE";
  92. char Percent1[]="COMMENT";
  93. char Percent2[]="PERCENT";
  94. char Percent3[]="EOL";
  95. char NoPercent1[]="NOCOMMENT";
  96. char NoPercent2[]="NOPERCENT";
  97. char NoPercent3[]="NOEOL";
  98. char EUC1[]="EUC";
  99. char NoEUC1[]="MSKANJI";
  100. char NoEUC2[]="SHIFTJIS";
  101. char Extended1[]="EXTENDED";
  102. char Standard1[]="STANDARD";
  103. char LaTeX1[]="LATEX";
  104. char TeX1[]="MUTEX";
  105. char TeX2[]="TEX";
  106. char One1[]="1000";
  107. char Two1[]="1095";
  108. char Three1[]="1200";
  109. char Four1[]="1440";
  110. char Five1[]="1728";
  111. char Six1[]="2074";
  112. char Seven1[]="2488";
  113. char One2[]="0.0";
  114. char Two2[]="0.5";
  115. char Three2[]="1.0";
  116. char Four2[]="2.0";
  117. char Five2[]="3.0";
  118. char Six2[]="4.0";
  119. char Seven2[]="5.0";
  120. char One3[]="0";
  121. char Three3[]="1";
  122. char Four3[]="2";
  123. char Five3[]="3";
  124. char Six3[]="4";
  125. char Seven3[]="5";
  126. /* Comment line maximum length */
  127. #define CommentLineMax 254
  128.  
  129. typedef char FileNameType[FileNameDOS+1];
  130. typedef char ExtensionType[ExtensionDOS+1];
  131. typedef char TotalNameType[TotalNameDOS+1];
  132. typedef char ParamType[ParamMax+1];
  133. typedef int FontType[FontMax+1];
  134. typedef FontType FontsType[SizeMax+1];
  135. typedef char CommentLineType[CommentLineMax+2]; /* note the 2 used */
  136. /* Run time parameters */
  137. struct RunTimeType {
  138.   FileNameType FileName;
  139.   ExtensionType Extension;
  140.   int ExtraSpace,Percent,LaTeX,EUC,Extended;
  141.   int Size;
  142. };
  143. /* Japanese punctuation information */
  144. struct PunctuationType {
  145.   /* Indicates .,!? present */
  146.   int OldMajorEOL,NewMajorEOL;
  147.   /* Indicates :; present */
  148.   int OldMinorEOL,NewMinorEOL;
  149.   /* Indicates `"([< and other openings present */
  150.   int OldOpening,NewOpening;
  151.   /* Indicates '")]> and other closings present */
  152.   int OldClosing,NewClosing;
  153.   /* Indicates Japanese center dot present */
  154.   int OldCenterDot,NewCenterDot;
  155.   /* Indicates Hiragana, Katakana, or Kanji present */
  156.   int OldJapanese,NewJapanese;
  157. };
  158. /* Scanning Information */
  159. struct ScanningType {
  160.   /* Current pass terminated */
  161.   int Done;
  162.   /* Indicates the current pass must produce output */
  163.   int Echo;
  164.   /* Indicates the current line is a comment */
  165.   int Comment;
  166.   /* Indicates current Bitmap immediately followed previous one */
  167.   int Immediate;
  168.   /* Indicates the last Roman character was a letter or digit */
  169.   int WasLetter;
  170.   /* Used for glue after a bitmap and before a roman */
  171.   int RomanMajorEOL,RomanMinorEOL,RomanOpening;
  172.   /* Non-comment Bitmap found */
  173.   int Found;
  174.   /* Processing the first character on the line which could be % */
  175.   int First;
  176.   /* Comment line which may contain Bitmaps */
  177.   CommentLineType CommentLine;
  178.   /* Current JIS24 Bitmap number */
  179.   int Bitmap;
  180.   /* Roman or first part of Bitmap read */
  181.   unsigned char Data1;
  182. };
  183.  
  184. void Delete(char *String, int Length)
  185. /* Delete the first Length characters of String */
  186. {
  187.   int Index;
  188.  
  189.   Index=0;
  190.   do String[Index]=String[Index+Length];
  191.   while (String[++Index]!='\0');
  192. }
  193.  
  194. /*----------------------------- EchoParameters ------------------------------*/
  195.  
  196. void EchoParameters(FILE *EchoFile, struct RunTimeType *RunTime)
  197. /* Echoes the current parameters in EchoFile */
  198. {
  199.   fprintf(EchoFile,"File=%s",RunTime->FileName);
  200.   if (RunTime->ExtraSpace) fprintf(EchoFile,"  Space");
  201.   else fprintf(EchoFile,"  No Space");
  202.   if (RunTime->Percent) fprintf(EchoFile,"  Added %%");
  203.   else fprintf(EchoFile,"  No Added %%");
  204.   if (RunTime->LaTeX) fprintf(EchoFile,"  LaTeX");
  205.   else fprintf(EchoFile,"  TeX");
  206.   if (RunTime->EUC) fprintf(EchoFile,"  EUC");
  207.   else fprintf(EchoFile,"  MS-kanji");
  208.   if (RunTime->Extended) fprintf(EchoFile,"  Extended");
  209.   else fprintf(EchoFile,"  Standard");
  210.   fprintf(EchoFile,"  Font Size=");
  211.   switch (RunTime->Size) {
  212.     case 1:fprintf(EchoFile,"1000"); break;
  213.     case 2:fprintf(EchoFile,"1095"); break;
  214.     case 3:fprintf(EchoFile,"1200"); break;
  215.     case 4:fprintf(EchoFile,"1440"); break;
  216.     case 5:fprintf(EchoFile,"1728"); break;
  217.     case 6:fprintf(EchoFile,"2074"); break;
  218.     case 7:fprintf(EchoFile,"2488"); break;
  219.   }
  220.   fprintf(EchoFile,".\n");
  221.   if (ferror(EchoFile)) exit(1);
  222. }
  223.  
  224. /*------------------------------ GetParameters ------------------------------*/
  225.  
  226. void SimpleQuery(char Title[], char ChoiceA[], char ChoiceB[], int *Answer)
  227. {
  228.   char JChar[2];
  229.   int Valid;
  230.  
  231.   do {
  232.     Valid=True;
  233.     printf("%s:\n",Title);
  234.     printf("   a)  %s\n",ChoiceA);
  235.     printf("   b)  %s\n",ChoiceB);
  236.     printf("Your choice? ");
  237.     if (ferror(stdout)) exit(1);
  238.     if (gets(JChar)==NULL) exit(1);
  239.     if (strlen(JChar)>1) exit(1);
  240.     JChar[0]=toupper(JChar[0]);
  241.     if (JChar[0]=='A') *Answer=True;
  242.     else
  243.       if (JChar[0]=='B') *Answer=False;
  244.       else { 
  245.         Valid=False; 
  246.         if (putchar('\7')==EOF) exit(1); 
  247.       }
  248.   } while (!Valid);
  249.   printf("\n");
  250.   if (ferror(stdout)) exit(